import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router';
import Register from '@/components/commerce/Register.vue';
import ProductList from '@/components/commerce/ProductList.vue';
import ProductDetail from '@/components/commerce/ProductDetail.vue';
import ShoppingCart from '@/components/commerce/ShoppingCart.vue';
import OrderHistory from '@/components/commerce/OrderHistory.vue';

const routes: InstanceType<typeof RouteRecordRaw>[] = [
  {
    path: '/',
    name: '/',
    redirect: '/products', // 先默认重定向到主界面和商品列表，后面再修改为到登陆界面
  },
  {
    path: '/register',
    name: 'register',
    component: Register,
    meta: { title: '注册' }
  },
  {
    path: '/products',
    name: 'products',
    component: ProductList,
    meta: { title: '商品列表' }
  },
  {
    path: '/productDetail/:id', // 动态路由，用于传递商品ID参数
    name: 'productDetail',
    component: ProductDetail,
    props: true, // 启用参数传递到组件的props属性
    meta: { title: '商品详情' }
  },
  {
    path: '/cart',
    name: 'cart',
    component: ShoppingCart,
    meta: { title: '购物车' }
  },
  {
    path: '/orders',
    name: 'orders',
    component: OrderHistory,
    meta: { title: '历史订单' }
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

export default router;
